#!/bin/sh

# 获取bash版本号（主版本号）
bash_version=$(bash --version | head -n1 | awk '{print $4}' | cut -d. -f1)
echo "当前bash版本号为：$bash_version"


# 判断bash版本是否大于等于4，如果不满足则提示并退出脚本
if [ "$bash_version" -lt 4 ]; then
    echo "此脚本需要bash版本4.0及以上才能运行，请升级bash版本后再尝试。"
    exit 1
fi

echo "一、定义Map:declare -A myMap=([\"myMap00\"]=\"00\" [\"myMap01\"]=\"01\")"
declare -A myMap=(["my00"]="00" ["my01"]="01")
myMap["my02"]="02"
myMap["my03"]="03"

echo "二、输出所有的key:"
echo ${!myMap[@]}

echo "三、输出所有value:"
echo ${myMap[@]}

echo "四、输出map的长度:"
echo ${#myMap[@]}

echo "五、遍历，根据key找到对应的value:"
for key in ${!myMap[*]};do
  echo "key:"$key
  echo "value:"${myMap[$key]}
done

echo "六、遍历所有的key:"
for key in ${!myMap[@]};do
  echo "key:"$key
  echo "value:"${myMap[$key]}
done

echo "七、遍历所有value:"
for val in ${myMap[@]};do
  echo "value:"$val
done